import React, { Fragment, useContext, useState } from 'react';
import { Button, Input, Modal } from 'antd';
import { ConfigsContext } from '../..';
export function InjectSchemaModel(props) {
  var schemaModelJSONCache = props.schemaModelJSONCache;
  var setSchemaList = useContext(ConfigsContext).setSchemaList;
  var _a = useState(false),
    visible = _a[0],
    setVisible = _a[1];
  var _b = useState(''),
    value = _b[0],
    setValue = _b[1];
  var handleInjectSchemaModel = function () {
    schemaModelJSONCache.current = JSON.parse(value);
    setSchemaList(schemaModelJSONCache.current.schemaList);
    setVisible(false);
  };
  return React.createElement(
    Fragment,
    null,
    React.createElement(
      Button,
      {
        type: 'primary',
        onClick: function () {
          return setVisible(true);
        }
      },
      '\u6CE8\u5165\u6A21\u677F'
    ),
    React.createElement(
      Modal,
      {
        title: '\u6CE8\u5165schemaModel',
        width: '50vw',
        bodyStyle: { height: '60vh', overflow: 'auto' },
        visible: visible,
        onOk: handleInjectSchemaModel,
        okButtonProps: { disabled: !value },
        onCancel: function () {
          return setVisible(false);
        }
      },
      React.createElement(Input.TextArea, {
        value: value,
        onChange: function (e) {
          return setValue(e.target.value);
        },
        allowClear: true,
        autoSize: { minRows: 6 },
        placeholder: '\u8BF7\u9ECF\u8D34JSON\u683C\u5F0F\u7684schemaModel\uFF5E'
      })
    )
  );
}
